package com.sskj.xyft.optional;

import com.hjq.toast.ToastUtils;
import com.sskj.base.utils.RxUtils;
import com.sskj.xyft.BasePresenter;
import com.sskj.xyft.api.Api;
import com.sskj.xyft.api.ApiObserver;
import com.sskj.xyft.market.bean.MarketData;

import java.util.List;

public class OptionalPresenter extends BasePresenter<OptionalFragment> {
    public void getMarketList(boolean showLoading) {
        Api.getInstance().optionalList()
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<List<MarketData>>(this, showLoading) {
                    @Override
                    public void onSuccess(List<MarketData> data) {
                        mView.stopRefresh();
                        mView.setData(data);
                    }


                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        mView.setData(null);
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                        mView.stopRefresh();
                    }
                });
    }

    // 删除自选
    //添加自选
    public void removeOptional(String code, boolean showLoading) {
        Api.getInstance().removeOptional(code)
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<Object>(this, showLoading) {
                    @Override
                    public void onSuccess(Object data) {
                        ToastUtils.show("删除成功");
                        getMarketList(false);
                    }

                });
    }
}
